package com.atguigu.guli.service.edu.controller.api;

import com.atguigu.commonutils.result.R;
import com.atguigu.guli.service.base.dto.CourseDto;
import com.atguigu.guli.service.edu.entity.Course;
import com.atguigu.guli.service.edu.entity.vo.ChapterVo;
import com.atguigu.guli.service.edu.entity.vo.WebCourseQueryVo;
import com.atguigu.guli.service.edu.entity.vo.WebCourseVo;
import com.atguigu.guli.service.edu.service.ChapterService;
import com.atguigu.guli.service.edu.service.CourseService;
import com.atguigu.guli.service.edu.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Api(tags = "课程列表")
@RestController
@RequestMapping("/api/edu/course")
public class ApiCourseController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private ChapterService chapterService;

    @ApiOperation("根据条件查询课程信息")
    @GetMapping("list")
    public R findByCondition(
            @ApiParam(value = "查询的对象",required = false) WebCourseQueryVo webCourseQueryVo
    ) {
        List<Course> courseList = courseService.findByCondition(webCourseQueryVo);
        return R.ok().data("courseList",courseList);
    }
    @ApiOperation("根据ID查询课程")
    @GetMapping("/get/{courseId}")
    public R getById(@ApiParam(value = "课程ID", required = true) @PathVariable String courseId){
        //查询讲师及描述信息与课程介绍信息
       WebCourseVo webCourseVo = courseService.findTeacherAndCourse(courseId);
        List<ChapterVo> chapterVoList = chapterService.nestedList(courseId);
        return R.ok().data("webCourseVo",webCourseVo).data("chapterVoList",chapterVoList);
    }

    @ApiOperation("根据课程id查询课程信息")
    @GetMapping("inner/get-course-dto/{courseId}")
    public CourseDto getCourseDtoById(
            @ApiParam(value = "课程ID",required = true)
            @PathVariable String courseId
    ) {
        return courseService.getCourseDtoById(courseId);
    }
}
